const { redis } = require('./index')
exports.VCode = {
  set: async (uuid, code) => {
    await redis.hmset(`InformationYouth_vcode:${uuid}`, 'code', code)
    await redis.expire(`InformationYouth_vcode:${uuid}`, 60)
  },
  get: async (uuid, field = 'code') => {
    const code = await redis.hget(`InformationYouth_vcode:${uuid}`, field)
    return code
  }
}
exports.ECode = {
  set: async (email, code, expire) => {
    await redis.hmset(
      `InformationYouth_ecode:${email}`,
      'code',
      code,
      'expire',
      expire,
      'email',
      email
    )
    await redis.expire(`InformationYouth_ecode:${email}`, 60 * 10)
  },
  get: async (email, field = 'code') => {
    const code = await redis.hget(`InformationYouth_ecode:${email}`, field)
    return code
  }
}
exports.Session = {
  set: async (sid, session, maxAge) => {
    await redis.set(
      `InformationYouth_Session:${sid}`,
      JSON.stringify(session),
      'EX',
      maxAge / 1000
    )
  },
  get: async (sid) => {
    const data = await redis.get(`InformationYouth_Session:${sid}`)
    return data
  },
  del: async (sid) => {
    await redis.del(`InformationYouth_Session:${sid}`)
  }
}
